package com.sharp.socket.io.controller;

import com.sharp.kernel.config.response.Response;
import com.sharp.kernel.config.response.ResponseHandler;
import com.sharp.kernel.vo.common.CommonResVO;
import com.sharp.socket.io.service.chat.ChatRoomManageService;
import com.sharp.socket.io.vo.room.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import java.util.List;

/**
 * Title: BaseChatRoomController
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2021/2/7 14:10
 * @description Project Name: Seed
 * @Package: com.srct.service.socketio.controller
 */
public class BaseChatRoomController {
    @Resource
    private ChatRoomManageService chatRoomManageService;

    @ApiOperation(value = "创建聊天室", notes = "创建聊天室")
    @RequestMapping(value = "/chat/room", method = RequestMethod.PUT)
    public ResponseEntity<Response<UpdateChatRoomRes>> createRoom(@RequestBody UpdateChatRoomReq req) {
        UpdateChatRoomRes res = chatRoomManageService.create(req);
        return ResponseHandler.generateResponse(res);
    }

    @ApiOperation(value = "获取聊天室列表", notes = "获取聊天室列表")
    @RequestMapping(value = "/chat/room", method = RequestMethod.GET)
    public ResponseEntity<Response<List<ChatRoomRes>>> getRoom(ChatRoomReq req) {
        List<ChatRoomRes> res = chatRoomManageService.getRoom(req);
        return ResponseHandler.generateResponse(res);
    }

    @ApiOperation(value = "修改聊天室", notes = "修改聊天室")
    @RequestMapping(value = "/chat/room", method = RequestMethod.POST)
    public ResponseEntity<Response<CommonResVO>> updateRoom(@RequestBody UpdateChatRoomReq req) {
        chatRoomManageService.update(req);
        return ResponseHandler.commonResponse();
    }

    @ApiOperation(value = "解散聊天室", notes = "解散聊天室")
    @RequestMapping(value = "/chat/room", method = RequestMethod.DELETE)
    public ResponseEntity<Response<CommonResVO>> destroyRoom(@RequestBody DeleteChatRoomReq req) {
        chatRoomManageService.delete(req);
        return ResponseHandler.commonResponse();
    }

    @ApiOperation(value = "修改聊天室成员", notes = "修改聊天室成员")
    @RequestMapping(value = "/chat/room/member", method = RequestMethod.POST)
    public ResponseEntity<Response<CommonResVO>> updateRoomMemberList(@RequestBody UpdateChatRoomMemberReq req) {
        chatRoomManageService.updateMember(req);
        return ResponseHandler.commonResponse();
    }

}
